package com.rf.richfitwheel.admin.sys.controller;


import com.rf.richfitwheel.admin.annotation.NoRepeatSubmit;
import com.rf.richfitwheel.admin.annotation.UserOperateLog;
import com.rf.richfitwheel.admin.contants.UrlConstant;
import com.rf.richfitwheel.admin.sys.model.AttTyp;
import com.rf.richfitwheel.admin.sys.model.BusTyp;
import com.rf.richfitwheel.admin.sys.model.SxOpinion;
import com.rf.richfitwheel.admin.sys.model.SysBank;
import com.rf.richfitwheel.admin.sys.service.BusTypService;
import com.rf.richfitwheel.admin.sys.vo.UserVO;
import com.rf.richfitwheel.admin.utils.UserUtil;
import com.rf.richfitwheel.common.utils.PageUtils;
import com.rf.richfitwheel.common.utils.R;
import groovy.util.logging.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping(UrlConstant.WEB_ADMIN_URL+"/bustyp")
public class BusTypController {

    @Autowired
    private BusTypService busTypService;


    /**
     * 分页查询业务列表
     */
    @UserOperateLog(module = "业务类型管理", methods = "queryPage", description = "分页查询业务列表")
    @PostMapping("/queryPageList")
    public R queryBusTypList(@RequestBody Map<String, Object> params) {
        PageUtils pageUtils = busTypService.queryPage(params);
        return R.ok().put("page", pageUtils);
    }

    /**
     * 根据id删除获取
     */
    @UserOperateLog(module = "业务类型管理", methods = "deleteBusTyp", description = "删除业务数据")
    @GetMapping("/delete/{id}")
    public R getPlanInf(@PathVariable("id") String id) {
        BusTyp busTyp = busTypService.selectById(id);
        busTypService.deleteAttByBusno(busTyp.getBusno());
        busTypService.deleteBusTyp(id);
        return R.ok();
    }

    /**
     * 修改业务&表单
     */
    @UserOperateLog(module = "业务类型管理", methods = "updateBusTypData", description = "修改业务&表单")
    @NoRepeatSubmit
    @PostMapping("/updateBusTypData")
    public R updateBusTypData(@RequestBody Map<String, Object> params) {
        UserVO user = UserUtil.getUser();
        busTypService.updateBusTypData(params, user);
        return R.ok();
    }

    /**
     * 保存业务&表单
     */
    @UserOperateLog(module = "业务类型管理", methods = "saveBusTyp", description = "保存业务&表单")
    @NoRepeatSubmit
    @PostMapping("/busTypAddData")
    public R saveBusTyp(@RequestBody Map<String, Object> params) {
        UserVO user = UserUtil.getUser();
        busTypService.saveBusTyp(params, user);
        return R.ok();
    }

    /**
     * 根据busno获取
     */
    @UserOperateLog(module = "业务类型管理", methods = "selectById", description = "根据id获取并删除附件")
    @GetMapping("/getAttListByBusno/{busno}")
    public R getAttListByBusno(@PathVariable("busno") String busno) {
        BusTyp busTyp = busTypService.selectByBusno(busno);
        List<AttTyp> attTyp = busTypService.getListByBusno(busTyp.getBusno());
        return R.ok().put("busTyp", busTyp).put("attTypDataList", attTyp);
    }

    /**
     * 查询附件的数据
     */
    @UserOperateLog(module = "业务类型管理", methods = "selectById", description = "根据id获取并删除附件")
    @GetMapping("/getListByBusno/{busno}")
    public R getListByBusno(@PathVariable("busno") String busno) {
        List<AttTyp> attTyps = busTypService.getListByBusno(busno);
        return R.ok().put("attTyps", attTyps);
    }

    /**
     * 根据id获取并重新赋值附件
     */
    @UserOperateLog(module = "业务类型管理", methods = "selectById", description = "根据id获取并删除附件")
    @GetMapping("/getListByBusId/{id}")
    public R getListByBusId(@PathVariable("id") String id) {
        BusTyp busTyp = busTypService.selectById(id);
        List<AttTyp> attTyp = busTypService.getListByBusno(busTyp.getBusno());
        return R.ok().put("busTyp", busTyp).put("attTypDataList", attTyp);
    }



    /**
     * 普通保存业务
     */
    @UserOperateLog(module = "业务类型管理", methods = "save", description = "保存业务")
    @NoRepeatSubmit
    @PostMapping("/save")
    public R saveBusTyp(@RequestBody BusTyp BusTyp) {
        if (BusTyp.getId() == null || "".equals(BusTyp.getId())) {
            busTypService.addBusTyp(BusTyp, UserUtil.getUser());
        }
        return R.ok();
    }


    /**
     * 普通保存业务
     */
    @UserOperateLog(module = "保存意见反馈", methods = "save", description = "保存业务")
    @NoRepeatSubmit
    @PostMapping("/saveSxOpinion")
    public R saveSxOpinion(@RequestBody Map<String, Object> params) {
        busTypService.saveSxOpinion(params, UserUtil.getUser());
        return R.ok();
    }
    /**
     * 普通保存业务
     */
    @UserOperateLog(module = "更新保存意见", methods = "save", description = "保存业务")
    @NoRepeatSubmit
    @PostMapping("/updateSxOpinion")
    public R updateSxOpinion(@RequestBody Map<String, Object> params) {
        busTypService.updateSxOpinion(params, UserUtil.getUser());
        return R.ok();
    }

    /**
     * 普通保存业务
     */
    @UserOperateLog(module = "更新保存意见", methods = "save", description = "保存业务")
    @NoRepeatSubmit
    @PostMapping("/updateSxOpinionOne")
    public R updateSxOpinionOne(@RequestBody SxOpinion sxOpinion) {
        busTypService.updateSxOpinionOne(sxOpinion, UserUtil.getUser());
        return R.ok();
    }

    /**
     * 分页查询业务列表
     */
    @UserOperateLog(module = "查询意见反馈", methods = "queryPage", description = "分页查询业务列表")
    @PostMapping("/querySxOpinionPage")
    public R querySxOpinionPage(@RequestBody Map<String, Object> params) {
        PageUtils pageUtils = busTypService.querySxOpinionPage(params);
        return R.ok().put("page", pageUtils);
    }

    /**
     * 分页查询业务列表
     */
    @UserOperateLog(module = "查询单条意见", methods = "queryPage", description = "分页查询业务列表")
    @GetMapping("/findSxOpinion/{id}")
    public R findSxOpinion(@PathVariable("id") String id) {
        SxOpinion sxOpinion = busTypService.findSxOpinion(id);
        return R.ok().put("sxOpinion", sxOpinion);
    }



    /**
     * 分页查询银行信息
     */
    @UserOperateLog(module = "查询银行信息", methods = "querySysBankPage", description = "查询银行信息")
    @PostMapping("/querySysBankPage")
    public R querySysBankPage(@RequestBody Map<String, Object> params) {
        PageUtils pageUtils = busTypService.querySysBankPage(params);
        return R.ok().put("page", pageUtils);
    }

    /**
     * 添加银行信息
     */
    @UserOperateLog(module = "添加银行信息", methods = "saveBankOne", description = "添加银行信息")
    @PostMapping("/saveBankOne")
    public R saveBankOne(@RequestBody SysBank sysBank) {
        return busTypService.saveBankOne(sysBank);
    }

    @UserOperateLog(module = "修改银行信息", methods = "updateBankOne", description = "修改银行信息")
    @PostMapping("/updateBankOne")
    public R updateBankOne(@RequestBody SysBank sysBank) {
        busTypService.updateBankOne(sysBank);
        return R.ok();
    }
    /**
     * 查询单条银行信息
     */
    @UserOperateLog(module = "查询单条银行信息", methods = "findBankOne", description = "查询单条银行信息")
    @GetMapping("/findBankOne/{id}")
    public R findBankOne(@PathVariable("id") String id) {
        SysBank sysBank = busTypService.findBankOne(id);
        return R.ok().put("sysBank", sysBank);
    }

    /**
     * 删除单条银行信息
     */
    @UserOperateLog(module = "删除单条银行信息", methods = "deleteBankOne", description = "删除单条银行信息")
    @GetMapping("/deleteBankOne/{id}")
    public R deleteBankOne(@PathVariable("id") String id) {
        busTypService.deleteBankOne(id);
        return R.ok();
    }


}

